package com.tencreat.mall.controller.admin;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.core.HttpResult;
import com.tencreat.domain.account.RechargeLimitChange;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.service.mall.IRechargeLimitChangeService;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * pc代采购额度记录Controller
 *
 * @author tencreat
 * @company 深圳腾创互联科技有限公司
 * @link https://tencreat.com
 * @since 2023-11-15
 */
@Api(tags = "pc代采购额度记录api")
@RestController
@RequestMapping("/rechargeLimitChange")
@RequiredArgsConstructor
public class AdminRechargeLimitChangeController extends BaseController {

    private final IRechargeLimitChangeService rechargeLimitConfigService;

    @ApiOperation(value = "查询代采购额度记录列表")
    @PostMapping("/list")
    HttpResult<IPage<RechargeLimitChange>> list(@RequestBody RechargeLimitChange rechargeLimitChange) {
        IPage<RechargeLimitChange> page = new Page<>(rechargeLimitChange.getPageNum(), rechargeLimitChange.getPageSize());
        return HttpResult.ok(rechargeLimitConfigService.page(page, rechargeLimitChange));
    }

    @ApiOperation(value = "导出代采购额度记录列表")
    @Log(title = "代采购额度记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    AjaxResult export(@RequestBody RechargeLimitChange rechargeLimitChange) {
        List<RechargeLimitChange> list = rechargeLimitConfigService.page(getMaxPage(), rechargeLimitChange).getRecords();
        ExcelUtil<RechargeLimitChange> util = new ExcelUtil<>(RechargeLimitChange.class);
        return util.exportExcel(list, "代采购额度记录");
    }

    @ApiOperation(value = "获取代采购额度记录详细信息")
    //@GetMapping(value = "/getInfo/{id}")
    HttpResult<RechargeLimitChange> getInfo(@PathVariable("id") Long id) {
        return HttpResult.ok(rechargeLimitConfigService.getById(id));
    }

    @ApiOperation(value = "新增代采购额度记录")
    @Log(title = "代采购额度记录", businessType = BusinessType.INSERT)
    //@PostMapping(value = "/add")
    HttpResult<Boolean> add(@RequestBody @Validated RechargeLimitChange rechargeLimitChange) {
        return to(rechargeLimitConfigService.save(rechargeLimitChange));
    }

    @ApiOperation(value = "修改代采购额度记录")
    @Log(title = "代采购额度记录", businessType = BusinessType.UPDATE)
    //@PostMapping(value = "/edit")
    HttpResult<Boolean> edit(@RequestBody @Validated RechargeLimitChange rechargeLimitChange) {
        return to(rechargeLimitConfigService.updateById(rechargeLimitChange));
    }

    @ApiOperation(value = "删除代采购额度记录")
    @Log(title = "代采购额度记录", businessType = BusinessType.DELETE)
   // @PostMapping("/remove")
    HttpResult<Boolean> remove(@RequestBody List<Long> ids) {
        return to(rechargeLimitConfigService.removeByIds(ids));
    }
}
